#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <unistd.h>
#include <string.h>

int main(int argc, char* argv[])
{
    int fd;
    int i;
    char *start;
    char buf[32];

    fd = open("/dev/vfb0", O_RDWR);
    if (fd == -1)
        goto fail;

    start = mmap(NULL, 32, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
    if (start == MAP_FAILED)
        goto fail;

    for (i = 0; i < 26; i++) {
        *(start + i) = 'a' + i;
    }
    *(start + i) = '\0';

    if (lseek(fd, 3, SEEK_SET) == -1)
        goto fail;
        
    if (read(fd, buf, 10) == -1)
        goto fail;

    buf[10] = '\n';
    puts(buf);

    munmap(start, 32);
    return 0;

fail:
    perror("mmp test");
    exit(EXIT_FAILURE);
}